define(function (require, exports, module) {
	var $ = require('../../libs/jquery.min.js');

    var Guid = function () {
        var guid = '';
        for (var i = 1; i <= 32; i++) {
            var n = Math.floor(Math.random() * 16.0).toString(16);
            guid += n;
            if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
                guid += '-';
        }
        return guid;
    };


    var mathNum = function (min, max) {
        return Math.random() * (max - min + 1) + min
    };
    var kingsConfig = {
        'attack': {
            name: '攻击',
            description: '结算时,增加对手一点受到的伤害量'
        },
        'attack+': {
            name: '攻击 (强力一击)',
            description: '结算时,增加对手两点受到的伤害量'
        },
        'attack++': {
            name: '攻击 (秒杀)',
            description: '结算时,增加对手五点受到的伤害量'
        },
        'back-his': {
            name: '移除手牌(对手)',
            description: '出牌后,将对手最后一张手牌移回牌库,当对手手中手牌少于3张时无效(手中最少有两张牌)'
        },
        'back-me': {
            name: '移除手牌(自己)',
            description: '出牌后,将自己最后一张手牌移回牌库,当自己手中手牌少于3张时无效(手中最少有两张牌)'
        },
        'change': {
            name: '交换手牌',
            description: '出牌后,将自己最后一张手牌和对手最后一张手牌进行交换'
        },
        'fire': {
            name: '破坏 1',
            description: '出牌后将对手桌面上的最后一张王牌摧毁(对手桌面上至少有一张王牌)'
        },
        'fire+': {
            name: '破坏 2',
            description: '出牌后将对手桌面上的最后两张张王牌摧毁(对手桌面上至少有一张王牌)'
        },
        'fire++': {
            name: '破坏 3',
            description: '出牌后将对手桌面上的全部王牌摧毁(对手桌面上至少有一张王牌)'
        },
        'shield': {
            name: '盾 ',
            description: '结算时,减少一点自己受到的伤害'
        },
        'shield+': {
            name: '盾 (盾墙)',
            description: '结算时,减少两点自己受到的伤害'
        },
        'shield++': {
            name: '盾 (绝对防御)',
            description: '结算时,减少五点自己受到的伤害'
        },
        'take-2': {
            name: '抽一张2',
            description: '从拍库中抽一张2到手牌,当桌面上(包括自己和对手的底牌)中有2的时候无效(没有任何牌从牌库中出现)'
        },
        'take-3': {
            name: '抽一张3',
            description: '从拍库中抽一张3到手牌,当桌面上(包括自己和对手的底牌)中有3的时候无效(没有任何牌从牌库中出现)'
        },
        'take-4': {
            name: '抽一张4',
            description: '从拍库中抽一张4到手牌,当桌面上(包括自己和对手的底牌)中有4的时候无效(没有任何牌从牌库中出现)'
        },
        'take-5': {
            name: '抽一张5',
            description: '从拍库中抽一张5到手牌,当桌面上(包括自己和对手的底牌)中有5的时候无效(没有任何牌从牌库中出现)'
        },
        'take-6': {
            name: '抽一张6',
            description: '从拍库中抽一张6到手牌,当桌面上(包括自己和对手的底牌)中有6的时候无效(没有任何牌从牌库中出现)'
        },
        'take-7': {
            name: '抽一张7',
            description: '从拍库中抽一张7到手牌,当桌面上(包括自己和对手的底牌)中有7的时候无效(没有任何牌从牌库中出现)'
        },
        'take-com': {
            name: '完美抽牌',
            description: '系统自动从牌库中抽一张最接近点数的牌,当不存在这样一张牌的时候无效(没有任何牌从牌库中出现)'
        },
        'play24': {
            name: '扩充上限(24)',
            description: '出牌后,改变结算上限为24'
        },
        'play27': {
            name: '扩充上限(27)',
            description: '出牌后,改变结算上限为27'
        }
    };

    var king = function (name, parent) {
        this.config = kingsConfig[name];
        this.html = $('<div class="king TA"><img src="./img/king/' + name + '.jpg" title="' + this.config.name + '"/></div>');
        this.parent = parent;
        var _this = this;
        this.html.hover(function () {
            _this.parent.message.html('<p style=" text-align: center; font-weight: bold">' + _this.config.name + '</p><p style=" text-align: center;">' + _this.config.description + '</p>');
        }, function () {
            _this.parent.message.html('');
        });
        this.id = null;
        this.html.click(function () {
            if (_this.event) {
                _this.event();
                _this.parent.message.html('');
            };

        });
    };
    king.prototype.SetUse = function (event) {
        this.event = event;

    };

    king.prototype.render = function () {
        return this.html;
    };

    var kings = function (message) {
        this.kingsArray = [];
        this.message = message;
        this.html = $('<div class="kings"></div>');
    };

    kings.prototype.render = function () {
        return this.html;
    };

    kings.prototype.append = function (name) {
        var _king = new king(name, this);
        this.kingsArray.push(_king);

        _king.html.css({
            'left': '600px',
            'transform': 'scale(1,1) translate(-100px,0)',
        });
        this.html.append(_king.render());
        var _length = this.kingsArray.length - 1;

        setTimeout(function () {
            _king.html.css({
                'transform': 'scale(4,4) translate(0,0)',
            });
            setTimeout(function () {
                _king.html.css({
                    'left': _length * 45,
                    'transform': 'scale(1,1)',
                });
            }, 2000);
        }, 5);

    };

    kings.prototype.setInventory = function (data) {
        this.Inventory = data;
    };




    var Inventory = function (kings, message) {
        this.html = $('<div class="Inventory"></div>');
        this.message = message;
        this.kings = kings;
        this.KingArray = {};
    };

    Inventory.prototype.appendKing = function (name) {
        var id = Guid();
        var _king = new king(name, this);
        _king.id = id;
        this.KingArray[id] = _king;
        this.html.append(_king.render());

        var _this = this;
        _king.SetUse(function () {
            _king.html.remove();
            delete _this.KingArray[id];
            // ajax
            _this.kings.append(name);
        });

    };
    Inventory.prototype.render = function () {
        return this.html;
    };




    return {
        kings: function (message) {
            return new kings(message)
        },
        Inventory: function (kings, message) {
            return new Inventory(kings, message)
        },
    };
});